/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.packetclient;

import com.lineage.server.ClientThread;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.packetserver.S_CoordinatesAbnormal;
import com.lineage.server.packetserver.S_Paralysis;
import com.lineage.server.utils.Teleportation;

/**
 * Class <code>C_CoordinatesAbnormal</code> 请求 座标异常重整.
 * 
 * @author jrwz
 * @version 2012-5-11下午01:41:01
 * @see com.lineage.server.packetclient
 * @since JDK1.7
 */
public final class C_CoordinatesAbnormal extends ClientBasePacket {

    /** 返回一个字符串，表示客户端的数据包类型。("[C] C_DropItem" 等). */
    private static final String C_COORDINATESABNORMAL = "[C] C_CoordinatesAbnormal";

    /**
     * 请求 座标异常重整.
     * 
     * @param abyte0
     *            资料
     * @param client
     *            客户端对象
     */
    public C_CoordinatesAbnormal(final byte[] abyte0, final ClientThread client) {
        super(abyte0);
        final int type = this.readC();
        // System.out.println("请求 座标异常重整:" + type);
        final L1PcInstance pc = client.getActiveChar();
        if (type == 127) {
            final int olderLocx = pc.getX();
            final int olderLocy = pc.getY();
            pc.setOlderLocX(olderLocx);
            pc.setOlderLocY(olderLocy);
            pc.sendPackets(new S_CoordinatesAbnormal());
        } else {
            pc.sendPackets(new S_Paralysis(S_Paralysis.TYPE_TELEPORT_UNLOCK,
                    false));
            pc.setTeleportX(pc.getOlderLocX());
            pc.setTeleportY(pc.getOlderLocY());
            pc.setTeleportMapId(pc.getMapId());
            pc.setTeleportHeading(pc.getHeading());
            Teleportation.actionTeleportation(pc);
        }
    }

    @Override
    public String getType() {
        return C_COORDINATESABNORMAL;
    }
}
